package com.example.demo.controller;

import com.example.demo.model.User;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//返回html网页
@Controller
@RequestMapping("/response")
public class ResponseController {
    @RequestMapping("/returnHtmlPage")
    public String returnHtmlPage() {
        return "/HelloYumu.html";
    }

        //返回数据
        @ResponseBody//既是方法注解也是类注解
        @RequestMapping("/returnData")
        public String returnData(){
            return "hahhahaha";
        }

        //返回HTML代码片段
    @RequestMapping("/returnHtml")
    @ResponseBody
    public String returnHtml(){
        return "<h1>Hello,Yumu</h1>";
    }

    //返回json
    @RequestMapping("/returnJson")
    @ResponseBody
    public User returnJson(){
        User user=new User();
        user.setName("yumu");
        //注意setAge内是没有双引号的
        user.setAge(22);
        return user;
    }

    //设置状态码
    @RequestMapping("/setStatus")
    @ResponseBody
    public User setStatus(HttpServletResponse response){
        User user=new User();
        user.setName("yumu");
        user.setAge(22);
        response.setStatus(500);
        return user;
    }



}
